﻿CREATE PROCEDURE [dbo].[FC_Product_Search]
@IdEntityF int,
@IdSegmentPL int,
@IdCliente int
as
begin
	SELECT 0 AS IdProduct, '' AS CodProduct, '' AS DesProduct, '' AS CodDesproduct, @IdEntityF AS IdEntityF, 0 AS IdEntityF, '' AS DesUOM, 0 AS IdSegmentPL 
	UNION ALL
	
	SELECT a.IdProduct, A.CodProduct, A.DesProduct, A.CodProduct +'	- '+ A.DesProduct as CodDesproduct, A.IdEntityF, A.IdUOM, b.DesUOM, A.IdSegmentPL
	FROM FC_Product A
	inner join FC_UOM B on A.IdUOM = b.IdUOM 
	left join FC_SalePrice C ON C.IdProduct = A.IdProduct
	WHERE A.IdEntityF = @IdEntityF 
	--AND A.IdSegmentPL = @IdSegmentPL
	AND ((@IdSegmentPL = 0) or (A.IdSegmentPL = @IdSegmentPL))
	AND C.IdCustomer = @IdCliente
end